package com.manager.controller;

import com.easyCode.feature.mybaits.CustomPage;
import com.easyCode.feature.result.ResponseResultAdvice;
import com.manager.entity.dto.SubCampusDto;
import com.manager.entity.vo.SubCampusVo;
import com.manager.service.ISubCampusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Positive;
import java.util.List;

@Validated
@RestController
@RequestMapping("/subCampus")
@RequiredArgsConstructor
@ResponseResultAdvice
@Api(tags = "分校区请求")
public class SubCampusController {
    private final ISubCampusService iSubCampusService;

    @ApiOperation("新增分校区(普通管理员和超级管理员)")
    @PostMapping("/save")
    public Integer saveSubCampus(@Validated SubCampusVo subcampusVo) {
        return iSubCampusService.saveSubCampus(subcampusVo);
    }

    @ApiOperation("根据id查询分校区(普通管理员和超级管理员)")
    @GetMapping("/{id}")
    public SubCampusDto getSubCampus(@Positive(message = "非法参数") @PathVariable("id") Integer id) {
        return iSubCampusService.getSubCampusById(id);
    }

    @ApiOperation("分页批量查询分校区(普通管理员和超级管理员)")
    @GetMapping("/list")
    public List<SubCampusDto> listSubCampus(CustomPage customPage) {
        return iSubCampusService.listSubCampus(customPage);
    }

    @ApiOperation("删除分校区(普通管理员和超级管理员)")
    @DeleteMapping("/{id}")
    public void delSubCampus(@Positive(message = "非法参数")@PathVariable("id") Integer id) {
        iSubCampusService.delSubCampusById(id);
    }
}
